var MongoClient = require('mongodb').MongoClient
var url = 'mongodb://localhost:27017/'
let conn = null

function getCollection(collecitonName) {
	return new Promise((resolve, reject) => {
		if (!conn) {
			MongoClient.connect(url, function (err, db) {
				if (err) throw err

				conn = db.db('reactproject')
				resolve(conn.collection(collecitonName))
			})
		} else {
			resolve(conn.collection(collecitonName))
		}
	})
}

module.exports = {
	getCollection,
}
